﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace The_Wumpers
{
	class Map
	{
		public Boolean updated = false;
		public Room[] rooms = new Room[30];

        public Wumpus wumper;
        public Player player1 = new Player();
		public Map() { }
		public Map(Room[] rooms)
		{
			this.rooms = rooms;
            makeABat();
            makeAPit();
            makeAWumpus();
		}

		public void makeABat()
		{
				
				int batCounter = 0;
				while (batCounter < 2)
				{
					int testInt;
					Random rnd = new Random();
					testInt = rnd.Next(1, 29);
					if (!rooms[testInt].ContainsBat && !rooms[testInt].ContainsPit)
					{
						rooms[testInt].ContainsBat = true;
						batCounter ++;
                        Console.WriteLine("Room " + testInt + " Now has a bat");
					}
				}
		}
		public void makeAPit()
		{
			//create integer
			int pitCounter = 0;
			while (pitCounter < 2)
			{
				int testInt;
				Random rnd = new Random();
				testInt = rnd.Next(1, 29);
				if (!rooms[testInt].ContainsBat && !rooms[testInt].ContainsPit)
				{
					rooms[testInt].ContainsPit = true;
					pitCounter ++;
                    Console.WriteLine("Room " + testInt + " Now has a Pit");
				}
			}
		}
		public void makeAWumpus()
		{
			Random rnd = new Random();
			int testInt = rnd.Next(1, 29);
			Wumpus wumper = new Wumpus(testInt);////////////////////////
			rooms[testInt].ContainsWumpus = true;
             this.wumper = wumper;
		}

		public int movePlayer()
		{
			if (rooms[player1.Location].ContainsBat)
			{
				ActivateBat(); return 1;
			}
			if (rooms[player1.Location].ContainsPit)
			{
				ActivatePit(); return 2;
			}
            if (rooms[player1.Location].ContainsWumpus)
            {
                return 0; ///////////////
            }
            else return 0;
		}
        public bool moveplayernorth()
        {
            if (rooms[player1.Location].NorthOpen == true)
            {
                player1.Location = rooms[player1.Location].north;
                return true;
            }
            else return false;

        }
        public bool moveplayernorthWest()
        {
            if (rooms[player1.Location].NorthWestOpen == true)
            {
                player1.Location = rooms[player1.Location].northWest;
                return true;
            }
            else return false;

        }
        public bool moveplayernorthEast()
        {
            if (rooms[player1.Location].NorthEastOpen == true)
            {
                player1.Location = rooms[player1.Location].northEast;
                return true;
            }
            else return false;

        }
        public bool moveplayersouth()
        {
            if (rooms[player1.Location].SouthOpen == true)
            {
                player1.Location = rooms[player1.Location].south;
                return true;
            }
            else return false;

        }
        public bool moveplayersouthWest()
        {
            if (rooms[player1.Location].SouthWestOpen == true)
            {
                player1.Location = rooms[player1.Location].southWest;
                return true;
            }
            else return false;

        }
        public bool moveplayersouthEast()
        {
            if (rooms[player1.Location].SouthEastOpen == true)
            {
                player1.Location = rooms[player1.Location].southEast;
                return true;
            }
            else return false;

        }

		public void ActivateBat()
		{
			rooms[player1.Location].ContainsBat = false;
			int batCounter = 0;
			while (batCounter < 1)
			{
				int testInt;
				Random rnd = new Random();
				testInt = rnd.Next(0, 29);
				if (!rooms[testInt].ContainsBat && !rooms[testInt].ContainsPit)
				{
					rooms[testInt].ContainsBat = true;
					batCounter++;
					player1.Location = rnd.Next(0,29);
				}
			}
            Console.WriteLine("A bat moved you to" + player1.Location);
		}
        public static void ThreadProc()
        {
            Application.Run(new StartScreen());
        }
		public void ActivatePit()
		{
            
            using (Form1 popUpForm = new Form1())
            {
                popUpForm.ShowDialog();
                if (popUpForm.correct == false)
                {
                    MessageBox.Show("You are stuck try again");
                }
                else { rooms[player1.Location].ContainsPit = false; player1.Location = 0; MessageBox.Show("You found your way out but youre where you started"); };
            }
            
		}

		public void awakeWumpus(Wumpus wumper)
		{
			wumper.EnumProperty = Wumpus.WumpusState.Awake;
		}

		public void asleepWumpus(Wumpus wumper)
		{
			wumper.EnumProperty = Wumpus.WumpusState.Asleep;
		}

		public void moveTheWumpus()
		{
			wumper.Location = wumper.Move(rooms);
            Console.WriteLine("The wumpus has moved to " + wumper.Location);
		}

 
	}


}
